package testJdk.commonUse.enmu;

class Gender {

    private String description;

    private Gender(String description) {
        this.description = description;
    }


    //1.将枚举对象藏起来
    private static final Gender female = new Gender("女");
    private static final Gender male = new Gender("男");

    //2.对外只提供静态方法
    public static Gender getFemale() {
        return female;
    }
    public static Gender getMale() {
        return male;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return "Gender{" +
                "description='" + description + '\'' +
                //递归死循环，会导致栈溢出
                /*"female='" + female + '\'' +
                "male='" + male + '\'' +*/
                '}';
    }
}

public class GenderTester{
    public static void main(String[] args) {
        Gender female = Gender.getFemale();
        System.out.println(female);
        Gender male = female.getMale();
        System.out.println(male);
    }
}